#include "Singleton.h"
#include "EventHandler.h"
#include "EventPoller.h"

#include <D3DX10math.h>
#include <D3D11.h>

class MiniMap : public Uncopyable, public EventHandler
{
	MiniMap();
	friend class Singleton<MiniMap>;
public:
	~MiniMap();

	void Draw();
	void DrawColourPick();
	void RenderMap();
		
	D3DXVECTOR4 GetPickedColour() const;
	bool GetCollided() const;

	bool GetMapRendered() const;
	void Reset();
	
	virtual void OnKeyDownEvent(const WPARAM& event) override;
	virtual void OnKeyUpEvent(const WPARAM& event) override;
	virtual void OnMouseMotionEvent(const LPARAM& event) override;
	virtual void OnMouseButtonDownEvent(const MSG& event) override;
	virtual void OnMouseButtonUpEvent(const MSG& event) override;

private:
	bool MouseIntersected();

private:
	int m_mouseX;
	int m_mouseY;
	D3DXVECTOR2 m_position;
	D3DXVECTOR2 m_screenPos; // pixels
	D3DXVECTOR2 m_scale;
	int m_width; // pixels
	int m_height; // pixels
	bool m_mapRendered;

	D3DXVECTOR4 m_pickedColour;

	ID3D11Texture2D* m_pRenderTargetTexture;
	ID3D11RenderTargetView* m_pRenderTargetView;
	ID3D11ShaderResourceView* m_pShaderResourceView;

	ID3D11Texture2D* m_pRTTGameObjects;
	ID3D11RenderTargetView* m_pRTVGameObjects;
	ID3D11ShaderResourceView* m_pSRVGameObjects;

	ID3D11Texture2D* m_pRTTGameObjectsColPick;
	ID3D11RenderTargetView* m_pRTVGameObjectsColPick;
	ID3D11ShaderResourceView* m_pSRVGameObjectsColPick;
	
	ID3D11Texture2D* m_pRTTFogOfWar;
	ID3D11RenderTargetView* m_pRTVFogOfWar;
	ID3D11ShaderResourceView* m_pSRVFogOfWar;
	ID3D11Texture2D* m_pRTTFogOfWarFin;
	ID3D11RenderTargetView* m_pRTVFogOfWarFin;
	ID3D11ShaderResourceView* m_pSRVFogOfWarFin;

	bool m_lArrowDown;
	bool m_rArrowDown;

	D3D11_BOX m_boundingBox; // in pixels
	D3DXVECTOR4 m_clearColour;

	int m_screenW;
	int m_screenH;
	
	bool m_lMouseButtonDown;
	bool m_mouseIntersected;

	float m_camRot;
};

typedef Singleton<MiniMap> TheMiniMap;